<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%@include file="/common/common.jsp" %>
    <link rel="stylesheet" href="${basePath}/css/layerPage.css${VERSION}"/>
</head>
<body>
<form id="form" name="form" class="form-horizontal" method="post" action="${basePath}/user/modifyPassword">
    <div class="panel-body">

        <div class="form-group">
            <label class="col-sm-3 control-label">登录名：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="loginName" name="loginName" value="${user.loginName}" disabled/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">用户姓名：</label>
            <div class="col-sm-9">
                <input type="text" class="col-sm-5" id="userName" name="userName" value="${user.userName}" disabled/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">密码：</label>
            <div class="col-sm-9">
                <input type="password" class="col-sm-5" id="password" name="password"/>

            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">确认密码：</label>
            <div class="col-sm-9">
                <input type="password" class="col-sm-5" id="confirmPassword" name="confirmPassword"/>
            </div>
        </div>
        <input type="hidden" name="userId" value="${user.userId}" />
        <button id="submit" type="submit" class="btn btn-success btn-submit">提交</button>
    </div>
</form>
<script type="text/javascript">
    jQuery(function ($) {
        var $form = $("#form");
        var $password = $("#password");
        var $confirmPassword = $("#confirmPassword");
        var $submit = $("#submit");

        $form.validate({
            errorClass: 'error-msg',
            rules: {
                password:{
                    required:true,
                    minlength: 6
                },
                confirmPassword:{
                    required: true,
                    minlength: 6,
                    equalTo: "#password"
                }
            },
            messages: {
                password:{
                    required: "密码必填",
                    minlength: "密码最少6位"
                },
                confirmPassword:{
                    required: "确认密码必填",
                    minlength: "密码最少6位",
                    equalTo: "与密码不一致"
                }
            },
            submitHandler: function(form) {
                $.ajax({
                    url:$form.attr("action"),
                    type: $form.attr("method"),
                    data: $form.serialize(),
                    dataType: "json",
                    cache: false,
                    beforeSend: function() {
                        $submit.prop("disabled", true);
                    },
                    success: function(data) {
                        if(data.status == '0'){
                            $submit.prop("disabled", false);
                            layer.confirm('密码修改成功！是否关闭窗口？',{icon:1}, function (index) {
                                parent.$("#grid-table").jqGrid().trigger("reloadGrid", [{page: 1}]);
                                parent.layer.close(parent.pageii);
                                return false
                            });
                        } else {
                            $submit.prop("disabled", false);
                            layer.alert(data, {
                                icon: 0,
                                skin: 'layui-layer-lan',
                                closeBtn: 0
                            });
                        }
                    },
                    error: function(xhr, textStatus, errorThrown) {
                        $submit.prop("disabled", false);
                        layer.alert("系统未知错误", {
                            icon: 0,
                            skin: 'layui-layer-lan',
                            closeBtn: 0
                        });
                    }
                });
            }
        });

    });
</script>
</body>
</html>
